home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Sound / Subspace68k / src / Subspace68k3.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-04  |  53.3 KB  |  1,524 lines

  1. #define P96 //SuRgEoN :for compatibility - still through cgfx
  2.  
  3.  
  4. #ifdef __PPC__
  5. #define MAXWIDTH  640
  6. #define MAXHEIGHT 480
  7. #else
  8. #define MAXWIDTH  640
  9. #define MAXHEIGHT 480
  10. #endif
  11.  
  12. #define NUMFIELDS 19
  13. #define NUMWAVES 12
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <time.h>
  19. #include <math.h>
  20.  
  21. #include <exec/types.h>
  22. #include <exec/libraries.h>
  23. #include <exec/memory.h>
  24. #include <exec/devices.h>
  25. #include <graphics/gfx.h>
  26. #include <graphics/gfxbase.h>
  27. #include <intuition/intuition.h>
  28. #include <cybergraphics/cybergraphics.h>
  29.  
  30. #include <proto/exec.h>
  31. #include <proto/dos.h>
  32. #include <proto/intuition.h>
  33. #include <proto/graphics.h>
  34. #include <proto/cybergraphics.h>
  35. #include <proto/icon.h>
  36. #include <proto/keymap.h>
  37. #include <devices/timer.h>
  38. #include <proto/timer.h>
  39.  
  40. #include <workbench/startup.h>
  41. #include <dos/dostags.h>
  42. //#include <graphics/gfxbase.h>
  43. //#include <cybergraphx/cybergraphics.h>
  44. //#include <libraries/picasso96.h>
  45. //#include <clib/picasso96_protos.h>
  46.  
  47. static int BytesPerRow;
  48. static BYTE *GfxAddr;
  49.  
  50. /*
  51. #ifndef __PPC__
  52. extern void ASM TurboUpdate68k(REG(a0,BYTE *), REG(a1,BYTE *),
  53.                                REG(d4,int), REG(d0,int), REG(d1,int),
  54.                                REG(d2,int), REG(d3,int));
  55. #endif
  56. */
  57.  
  58. #ifdef __SASC
  59. struct Library *PPCLibBase;
  60. #include <PowerUP/PPCLib/tasks.h>
  61. ULONG   PPCCallOS(struct Caos*);
  62. ULONG   PPCSetTaskAttrs(void*, struct TagItem*);
  63.  
  64. #define PPCSetTaskAttrs(TaskObject, Tags)       _PPCSetTaskAttrs(PPC_BASE_NAME, TaskObject, Tags)
  65. static __inline ULONG _PPCSetTaskAttrs(void *PPCLibBase, void*TaskObject, struct TagItem*Tags) {
  66.         struct Caos     MyCaos;
  67.         MyCaos.M68kCacheMode    =       IF_CACHEFLUSHALL;
  68.         MyCaos.PPCCacheMode     =       IF_CACHEFLUSHALL;
  69.         MyCaos.a0               =(ULONG) TaskObject;
  70.         MyCaos.a1               =(ULONG) Tags;
  71.         MyCaos.caos_Un.Offset   =       (-192);
  72.         MyCaos.a6               =(ULONG) PPCLibBase;    
  73.         return((ULONG)PPCCallOS(&MyCaos));
  74. }
  75. #endif
  76.  
  77.  
  78. #include "TrackInfo.h"
  79.  
  80. BOOL PluginInit(int argc, char **argv);
  81. void PluginExit(void);
  82. void PluginLoop(void); //mainloop for viasualization effects
  83. void ShowRequester(char *Text, char *Button);
  84. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri);
  85. void MyDeletePort(struct MsgPort *mp);
  86.  
  87. /***************************************************************************/
  88. /* This is the global variables section. Don't change anything here unless */
  89. /* you know what you're doing!                                             */
  90. /***************************************************************************/
  91.  
  92. BYTE             PluginSignal, InfoSignal, ConfigSignal;
  93. ULONG            PluginMask,   InfoMask,   ConfigMask;
  94. BOOL             Accepted;
  95. struct Process   *PluginTask;
  96. struct MsgPort   *PluginMP;
  97. struct MsgPort   *PluginRP;
  98. struct TrackInfo *tinfo;
  99.  
  100. #ifdef __SASC
  101. struct Library     *TimerBase;
  102. #else
  103.  #ifdef __VBCC__ //SuRgEoN
  104. struct Library      *TimerBase = NULL;
  105.  #else
  106. struct Device      *TimerBase;
  107.  #endif
  108. #endif
  109. struct MsgPort     *TimerMP;
  110. struct timerequest *TimerIO = NULL;
  111. struct EClockVal   ev1;
  112. struct EClockVal   ev2;
  113. BYTE               TimerError = -1;
  114. ULONG              EFreq=0;
  115. ULONG              TimerMask;
  116.  
  117. UWORD   TrackInfoPos = 1;
  118.  
  119. UWORD   *PluginRawL;
  120. UWORD   *PluginRawR;
  121. WORD    *PluginSamples;
  122. UWORD   *SpecRawL;
  123. UWORD   *SpecRawR;
  124. WORD *SampleRaw;
  125.  
  126. struct PluginMessage {
  127.         struct Message   msg;
  128.         ULONG            PluginMask;
  129.         struct Process   *PluginTask;
  130.         UWORD            **SpecRawL;
  131.         UWORD            **SpecRawR;
  132.         UWORD            Accepted;
  133.         UWORD            reserved0;
  134.         ULONG            InfoMask;
  135.         struct TrackInfo **tinfo;
  136.         ULONG            ConfigMask;
  137.         WORD             **SampleRaw;
  138. };
  139.  
  140. BOOL OpenTimer(void);
  141. void CloseTimer(void);
  142. void StartTimer(void);
  143.  
  144. /***************************************************************************/
  145. /* This is the main part. Again, don't change anything here if you haven't */
  146. /* got a very good reason to do so!                                        */
  147. /***************************************************************************/
  148.  
  149. int main(int argc, char **argv) {
  150.         struct PluginMessage *PluginMsg;
  151.         struct PluginMessage *ReplyMsg;
  152.  
  153.  
  154.         /* Allocate all user resources */
  155.         if(PluginInit(argc, argv)) {
  156.                 /* Check if a plugin capable instance of AmigaAMP is running */
  157.                 if(PluginMP=FindPort("AmigaAMP plugin port"))   {
  158.                         /* Allocate some sigbits for receiving signals FROM AmigaAMP */
  159.                         PluginSignal = AllocSignal(-1);
  160.                         ConfigSignal = AllocSignal(-1);
  161.                         InfoSignal   = AllocSignal(-1);
  162.                         PluginTask   = (struct Process *)FindTask(NULL);
  163.  
  164.                         if(PluginSignal != -1 && InfoSignal != -1 && PluginSignal != -1) {
  165.                                 PluginMask = 1L << PluginSignal;
  166.                                 ConfigMask = 1L << ConfigSignal;
  167.                                 InfoMask   = 1L << InfoSignal;
  168.  
  169.                                 /* Allocate a message and reply port for sending messages TO AmigaAMP */
  170.                                 #if defined (__SASC) || defined (__VBCC__) //SuRgEoN
  171. #ifdef __PPC__
  172.                                 PluginMsg=PPCAllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  173. #else
  174.                                 PluginMsg=AllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  175. #endif
  176.                                 PluginRP=(struct MsgPort*)MyCreatePort(0,0);
  177.                                 #else
  178.                                 PluginMsg=AllocVecPPC(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR, 0);
  179.  
  180.                                 PluginRP=(struct MsgPort*)CreatePort(0,0);
  181.                                 #endif
  182.  
  183.                                 /* Tell AmigaAMP all the details it needs to know */
  184.                                 PluginMsg->msg.mn_Node.ln_Type = NT_MESSAGE;
  185.                                 PluginMsg->msg.mn_Length       = sizeof(struct PluginMessage);
  186.                                 PluginMsg->msg.mn_ReplyPort    = PluginRP;
  187.                                 PluginMsg->PluginMask          = PluginMask;
  188.                                 PluginMsg->PluginTask          = PluginTask;
  189.                                 PluginMsg->SpecRawL            = &SpecRawL;
  190.                                 PluginMsg->SpecRawR            = &SpecRawR;
  191.                                 PluginMsg->InfoMask            = InfoMask;
  192.                                 PluginMsg->tinfo               = &tinfo;
  193.                                 PluginMsg->ConfigMask          = ConfigMask;
  194.                                 PluginMsg->SampleRaw           = &SampleRaw;
  195.                                 PutMsg(PluginMP, (struct Message *)PluginMsg);
  196.                                 /* Wait for a reply */
  197.                                 WaitPort(PluginRP);
  198.                                 /* Let's see if AmigaAMP accepted our registration attempt */
  199.                                 if(ReplyMsg = (struct PluginMessage *)GetMsg(PluginRP)) Accepted=ReplyMsg->Accepted;
  200.                                 else Accepted=FALSE;
  201.  
  202.                                 if(Accepted) {
  203.                                         /* If it did, start the plugin loop */
  204.                                         printf("Init ok! - entering plugin loop\n");
  205.                                         PluginLoop();
  206.  
  207.                                         /* Tell AmigaAMP that this plugin is going down */
  208.                                         PluginMsg->PluginMask          = 0;
  209.                                         PluginMsg->PluginTask          = NULL;
  210.                                         PluginMsg->SpecRawL            = NULL;
  211.                                         PluginMsg->SpecRawR            = NULL;
  212.                                         PluginMsg->ConfigMask          = 0;
  213.                                         PluginMsg->InfoMask            = 0;
  214.                                         PluginMsg->tinfo               = NULL;
  215.                                         PluginMsg->SampleRaw           = NULL;
  216.                                         PutMsg(PluginMP, (struct Message *)PluginMsg);
  217.                                         /* Wait for confirmation before going on! */
  218.                                         WaitPort(PluginRP);
  219.                                         GetMsg(PluginRP);
  220.                                         /* Now that AmigaAMP knows that we're gone, we can quit */
  221.                                 }
  222.                                 else {
  223.                                         /* If AmigaAMP didn't accept us, tell the user about it */
  224.                                         ShowRequester("Plugin rejected by AmigaAMP!\nPerhaps there's another one running.", "Abort");
  225.                                 }
  226.  
  227.                                 /* Free all resources */
  228.                                 #ifdef __SASC
  229.  
  230.                                         PPCFreeVec(PluginMsg);
  231.                                         MyDeletePort(PluginRP);
  232.                                 #else
  233.                                         #ifndef PPC__ //SuRgEoN
  234.                                         FreeVec(PluginMsg);
  235.                                         DeletePort(PluginRP);
  236.                                         #else
  237.                                         FreeVecPPC(PluginMsg);
  238.                                         DeletePort(PluginRP);
  239.                                         #endif
  240.                                 #endif
  241.                         }
  242.                         else {
  243.                                 ShowRequester("Signal allocation failure!", "Abort");
  244.                         }
  245.                         if(PluginSignal != -1) FreeSignal(PluginSignal);
  246.                         if(ConfigSignal != -1) FreeSignal(ConfigSignal);
  247.                         if(InfoSignal   != -1) FreeSignal(InfoSignal);
  248.                 }
  249.                 else {
  250.                         ShowRequester("Could not find message port!\nAmigaAMP probably not running.", "Abort");
  251.                 }
  252.         }
  253.         else {
  254.                 ShowRequester("Plugin initialisation failed!", "Ok");
  255.         }
  256.         /* Free all user resources */
  257.         PluginExit();
  258. }
  259.  
  260. /*****************************************************************************/
  261. /* Ok, now for the individual plugin sourcecode. Everything below should be  */
  262. /* changed to your needs.                                                    */
  263. /* Just like before, we start with the global variables section              */
  264. /*****************************************************************************/
  265.  
  266. void InitWave(UBYTE WaveNum, ULONG BufNum);
  267. void CalcWave(UBYTE WaveNum, ULONG BufNum);
  268. void DrawWave(LONG *WaveX, LONG *WaveY, ULONG Width, ULONG Height, UBYTE WaveNum, ULONG BufNum);
  269.  
  270. void InitField(LONG *Zoom, ULONG Width, ULONG Height);
  271. void PrepareConstants(UBYTE FieldNum);
  272. void CalcLine(LONG *Zoom, ULONG Width, ULONG Height, UBYTE FieldNum);
  273. void MakeCMap(void);
  274. void Blur(UBYTE *PixelC, UBYTE *PixelD);
  275. void ReColor(void);
  276. void MakeTitle(void);
  277. float rnd(float max);
  278. float sgn(float val);
  279.  
  280. const char VersionString[]="\0$VER: Subspace68k 1.0 (14.03.01)";
  281. const char Line1[]="Subspace";
  282. const char Line2[]="by Thomas Wenzel";
  283.  
  284. #define PRECISION PRECISION_EXACT
  285.  
  286. struct IntuitionBase *IntuitionBase = NULL;
  287. struct GfxBase *GfxBase      = NULL;
  288. struct Library *IconBase     = NULL;
  289. struct Library *KeymapBase   = NULL;
  290. struct Library *AslBase      = NULL;
  291. struct Library *GadToolsBase = NULL;
  292. struct Library *CyberGfxBase = NULL;
  293. struct Library *P96Base = NULL;
  294. struct Screen  *PluginScreen = NULL;
  295. struct Window  *PluginWin    = NULL;
  296. struct RastPort *rp;
  297. struct ViewPort *vp;
  298.  
  299.  
  300. struct EClockVal ev1;
  301. struct EClockVal ev2;
  302.  
  303.  
  304. ULONG ModeID;
  305. ULONG WinMask;
  306.  
  307. UBYTE *PixelD;
  308. UBYTE *PixelC;
  309. ULONG *Colour;
  310.  
  311. UWORD *EmptyPointer;
  312.  
  313. char InfoLine[256];
  314.  
  315. LONG Zoom[MAXWIDTH*MAXHEIGHT];
  316. LONG Zoom2[MAXWIDTH*MAXHEIGHT];
  317. LONG WaveX[MAXWIDTH*2];
  318. LONG WaveY[MAXWIDTH*2];
  319. LONG WaveX2[MAXWIDTH*2];
  320. LONG WaveY2[MAXWIDTH*2];
  321.  
  322. ULONG MidR[4], MidG[4], MidB[4];
  323. ULONG DisplayFPS;
  324. ULONG ShowWave;
  325. ULONG LimitFPS;
  326. #ifdef __PPC__
  327. ULONG ScreenSize = 100;
  328. #else
  329. ULONG ScreenSize = 55;
  330. #endif
  331. #ifdef PPC
  332. ULONG Width      = 320;
  333. ULONG Height     = 240;
  334. ULONG HalfHeight = 120;
  335. #else
  336. ULONG Width      = 256; //256*192    60, 256, 170
  337. ULONG Height     = 180; //100 with ScreenSize 66!
  338. ULONG HalfHeight = 90;
  339. #endif
  340. #ifndef __PPC__
  341. ULONG Woffset     = 32;// 32 for width 256
  342. #else
  343. ULONG Woffset     = 0;
  344. #endif
  345.  
  346. ULONG Cutoff     = 1;
  347. ULONG InfoCount;
  348. ULONG FrameCountLow;
  349. ULONG FrameCountHigh;
  350. ULONG FrameCountWave;
  351. ULONG FrameCountField;
  352. ULONG TimeWave;
  353. ULONG DestWaveNum;
  354. ULONG DestWaveBuffer;
  355. float WaveMorph;
  356. ULONG MidRdst[3], MidGdst[3], MidBdst[3];
  357. ULONG LineToCalc;
  358. UBYTE FieldToCalc;
  359. UBYTE WaveToCalc, WaveToCalc0, WaveToCalc1;
  360. UBYTE PrevField;
  361.  
  362. /****************************************************************************/
  363. /* This function will be called once when the plugin is started. You should */
  364. /* allocate all needed resources here. Return TRUE if all went well.        */
  365. /****************************************************************************/
  366.  
  367. BOOL PluginInit(int argc, char **argv) {
  368.         long i,xs,ys,xd,yd,ysp,ydp;
  369.         float xf,yf;
  370.         UBYTE **ttypes = 0; //VBCC
  371.         char *str;
  372.         struct DiskObject *IconObj = NULL; //VBCC
  373.         struct WBStartup  *WBStart = NULL; //VBCC
  374.         #ifdef __SASC
  375.         void *ThisTask;
  376.         #else
  377.         struct TaskPPC *ThisTask;
  378.         #endif
  379.         WORD Length;
  380.  
  381.   char *module = "CGfx_Init: ";
  382.  
  383. #ifdef __PPC__
  384.         struct TagItem ModeIDtags[] = {
  385.                 CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 240, TAG_DONE};
  386. #else
  387. /*
  388.         struct TagItem ModeIDtags[] = {
  389.                 CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 200, TAG_DONE};
  390. */
  391. /*
  392.         struct TagItem ModeIDtags[] = {CYBRMREQ_MinWidth, 320,  CYBRMREQ_MinHeight, 200, CYBRMREQ_MaxHeight, 240, TAG_DONE};
  393. */
  394.  
  395.   int DispID, ScrWidth, ScrHeight;
  396.   static short ColorModel[] = {PIXFMT_LUT8,-1};
  397.   struct TagItem CyberModeTags[] =
  398.   {
  399.    CYBRMREQ_MinWidth, 320, CYBRMREQ_MinHeight, 200, CYBRMREQ_MaxWidth, 320, CYBRMREQ_MaxHeight, 240, CYBRMREQ_CModelArray,(ULONG)ColorModel, TAG_DONE,0
  400.   };
  401.  
  402.  
  403. #endif
  404.         AslBase=OpenLibrary("asl.library", 0);
  405.         if(!AslBase) {
  406.                 ShowRequester("Can't open asl.library!", "Abort");
  407.                 return(FALSE);
  408.         }
  409.  
  410.         IconBase=OpenLibrary("icon.library", 0);
  411.         if(!IconBase) {
  412.                 ShowRequester("Can't open icon.library!", "Abort");
  413.                 return(FALSE);
  414.         }
  415.  
  416.         KeymapBase=OpenLibrary("keymap.library", 0);
  417.         if(!KeymapBase) {
  418.                 ShowRequester("Can't open keymap.library!", "Abort");
  419.                 return(FALSE);
  420.         }
  421.  
  422.         IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library", 0);
  423.         if(!IntuitionBase) {
  424.                 ShowRequester("Can't open intuition.library!", "Abort");
  425.                 return(FALSE);
  426.         }
  427.  
  428.         GadToolsBase=OpenLibrary("gadtools.library", 0);
  429.         if(!GadToolsBase) {
  430.                 ShowRequester("Can't open gadtools.library!", "Abort");
  431.                 return(FALSE);
  432.         }
  433.  
  434.         if(!(GfxBase= (struct GfxBase*) OpenLibrary("graphics.library", 0)))
  435.        {
  436.                 ShowRequester("Can't open graphics.library!", "Abort");
  437.                 return(FALSE);
  438.         }
  439.  
  440.         if(GfxBase->LibNode.lib_Version < 39) {
  441.                 ShowRequester("This plugin requires AmigaOS 3.0 or greater!", "Abort");
  442.                 return(FALSE);
  443.         }
  444.         if (!(CyberGfxBase = (struct Library *) OpenLibrary("cybergraphics.library", 0)))
  445.        {
  446.                 ShowRequester("This plugin requires CyberGraphX v3 or higher!", "Abort");
  447.                 return(FALSE);
  448.         }
  449.  
  450.       P96Base = (struct Library *) OpenLibrary("Picasso96API.library",0);
  451.         if(!P96Base) {
  452.                 ShowRequester("This plugin requires Picasso96", "Abort");
  453.                 return(FALSE);
  454.         }
  455.  
  456.         #ifdef __SASC
  457.                 /* Increase the priority of the 68k mirror task */
  458.                 SetTaskPri(FindTask(NULL), 15);
  459.                 /* Increase our own priority (if it only would work...) */
  460.                 PPCSetTaskAttr(PPCTASKTAG_PRIORITY, 15);
  461.         #else
  462.                 #ifdef __VBCC__
  463.         //              SetTaskPri(FindTask(NULL), 15);
  464.                 #else
  465.                 /* Increase our own priority */
  466.                 ThisTask = FindTaskPPC(NULL);
  467.                 SetNiceValue(ThisTask, -15);
  468.                 #endif
  469.         #endif
  470.  
  471.         WBStart=(struct WBStartup *)argv;
  472.  
  473. // if(argc==0) printf("IconName: %s\n", WBStart->sm_ArgList[0].wa_Name);
  474.  
  475.         if(argc==0) IconObj=GetDiskObject(WBStart->sm_ArgList[0].wa_Name);
  476.         else        IconObj=GetDiskObject(argv[0]);
  477.  
  478.         LimitFPS = 999;
  479.  
  480.         if(IconObj) {
  481.                 if(str=FindToolType(IconObj->do_ToolTypes,"MAXFPS"))
  482.                 {
  483.                         LimitFPS = atol(str);
  484.                 }
  485.  
  486.                 if(str=FindToolType(IconObj->do_ToolTypes,"RESOLUTION"))
  487.                 {
  488.                         if(stricmp(str,"high") == 0) {
  489.                                 Width      = 640;
  490.                                 Height     = 480;
  491.                                 ScreenSize = 66;
  492.                         }
  493.                         else {
  494. #ifdef __PPC__
  495.                                 Width      = 320;
  496.                                 Height     = 240;
  497.                                 ScreenSize = 100;
  498. #else
  499.                                 Width      = 256;
  500.                                 Height     = 180;
  501.                                 ScreenSize = 55;
  502. #endif
  503.  
  504.                         }
  505.                 }
  506.  
  507.                 if(str=FindToolType(IconObj->do_ToolTypes,"SCREENSIZE"))
  508.                 {
  509.                         ScreenSize = atol(str);
  510.                 }
  511.         FreeDiskObject(IconObj);
  512.         }
  513.  
  514.         if(ttypes=(UBYTE**)ArgArrayInit(argc, argv)) {
  515.                 str=(char*)ArgString(ttypes, "MAXFPS", "0");
  516.                 LimitFPS = atol(str);
  517.  
  518.                 str=(char*)ArgString(ttypes, "RESOLUTION", "low");
  519.                 if(stricmp(str,"high") == 0) {
  520.                         Width      = 640;
  521.                         Height     = 480;
  522.                         ScreenSize = 66;
  523.                         ShowWave   = 1;
  524.                 }
  525.                 else {
  526. #ifdef __PPC__
  527.                         Width      = 320;
  528.                         Height     = 240;
  529.                         ScreenSize = 100;
  530. #else
  531.                         Width      = 256; //240
  532.                         Height     = 180; //190
  533.                         ScreenSize = 55;//60
  534. #endif
  535.                         ShowWave   = 0;
  536.                 }
  537.  
  538.                 if(str=(char*)ArgString(ttypes, "SCREENSIZE", NULL)) {
  539.                         ScreenSize = atol(str);
  540.                 }
  541.  
  542.                 ArgArrayDone();
  543.         }
  544. #ifndef PPC
  545.         if(LimitFPS == 0)  LimitFPS = 999;
  546.         if(LimitFPS > 999) LimitFPS = 999;
  547. #else
  548.     LimitFPS = 10;
  549. #endif
  550.         if(ScreenSize <  25) ScreenSize =  25;
  551.         if(ScreenSize > 100) ScreenSize = 100;
  552.  
  553.         Cutoff = Height * (100-ScreenSize) / 200;
  554.         if(Cutoff <   1) Cutoff =   1;
  555.         if(Cutoff > 200) Cutoff = 200;
  556.  
  557. //        ModeIDtags[1].ti_Data = Width;
  558. //        ModeIDtags[2].ti_Data = Height;
  559. //        CyberModeTags[1].ti_Data = Width;
  560. //        CyberModeTags[2].ti_Data = Height;
  561.  
  562.         HalfHeight = Height/2;
  563.  
  564.         #if defined (__SASC) || defined (__VBCC__)
  565.                 #ifdef __PPC__
  566.                 PixelD       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  567.                 PixelC       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  568.                 Colour       = PPCAllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  569.                 EmptyPointer = PPCAllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  570.                 #else //68k
  571.                 PixelD       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  572.                 PixelC       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  573.                 Colour       = AllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  574.                 EmptyPointer = AllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  575.                 #endif
  576.         #else
  577.                 PixelD       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  578.                 PixelC       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  579.                 Colour       = AllocVecPPC(770*4,        MEMF_PUBLIC|MEMF_CLEAR, 0);
  580.                 EmptyPointer = AllocVecPPC(512,          MEMF_CHIP|MEMF_CLEAR,   0);
  581.         #endif
  582.  
  583.         OpenTimer();
  584.  
  585.         if(PixelD==NULL || PixelC==NULL) {
  586.                 ShowRequester("Out of memory for graphics buffers!", "Abort");
  587.                 return(FALSE);
  588.         }
  589.  
  590.         srand(time(NULL));
  591.  
  592.         MidR[0] = 230;
  593.         MidG[0] = 230;
  594.         MidB[0] = 230;
  595.  
  596.         MidR[1] = 86;
  597.         MidG[1] = 86;
  598.         MidB[1] = 170;
  599.  
  600.         MidR[2] = 25;
  601.         MidG[2] = 25;
  602.         MidB[2] = 100;
  603.  
  604.         MidR[3] = 0;
  605.         MidG[3] = 0;
  606.         MidB[3] = 0;
  607.  
  608.         MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  609.         MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  610.         MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  611.  
  612.         MidRdst[1] = (UBYTE)(rand()>>25) + 96;
  613.         MidGdst[1] = (UBYTE)(rand()>>25) + 96;
  614.         MidBdst[1] = (UBYTE)(rand()>>25) + 96;
  615.  
  616.         MidRdst[2] = (UBYTE)(rand()>>25) + 64;
  617.         MidGdst[2] = (UBYTE)(rand()>>25) + 64;
  618.         MidBdst[2] = (UBYTE)(rand()>>25) + 64;
  619.  
  620.         DisplayFPS      = 0;
  621.         InfoCount       = 0;
  622.         FrameCountLow   = 0;
  623.         FrameCountHigh  = 0;
  624.         FrameCountWave  = 0;
  625.         FrameCountField = 0;
  626.         TimeWave        = 0;
  627.         DestWaveNum     = 1;
  628.         DestWaveBuffer  = 1;
  629.         WaveMorph       = 0.0;
  630.         LineToCalc      = 0;
  631.         WaveToCalc      = 0;
  632.         WaveToCalc0     = 0;
  633.  
  634.         FieldToCalc     = (UBYTE)(rand() % NUMFIELDS);
  635.         WaveToCalc1     = (UBYTE)(rand() % NUMWAVES);
  636.  
  637. //      FieldToCalc   = 0; //10=endblur;16=radial;2=tunnel
  638. //      WaveToCalc1   = 1;
  639. //1=tunnel;2=lines;3=radar;4=flower;5=solsweep;6=xx;7=chaoticlines;8=circwaves;9=occludinglines;10=quad;11=;
  640. //      FieldToCalc   = NUMFIELDS-1;
  641. //      WaveToCalc1   = NUMWAVES-1;
  642.  
  643.  
  644.         PrepareConstants(FieldToCalc);
  645.  
  646.         MakeCMap();
  647.  
  648. #ifdef P96
  649. //      ModeID=CModeRequestTagList(NULL, ModeIDtags);
  650. if (!(DispID = CModeRequestTagList(NULL,CyberModeTags)))
  651. {
  652.                 ShowRequester("Could not find suitable screen mode!", "Abort");
  653.                 return(FALSE);
  654. };
  655.  
  656. //        ModeID=p96RequestModeIDTagList(ModeIDtags);
  657. #else
  658.         ModeID=BestCModeIDTagList(NULL, ModeIDtags);
  659. #endif
  660. /*
  661.         if(ModeID == INVALID_ID) {
  662.                 ShowRequester("Could not find suitable screen mode!", "Abort");
  663.                 return(FALSE);
  664.         }
  665. */        
  666. /*
  667.         PluginScreen=OpenScreenTags(NULL, SA_DisplayID, ModeID, SA_Depth, 8, SA_Width, Width, SA_Height, Height, SA_SharePens, TRUE, SA_ShowTitle, FALSE, SA_Quiet, TRUE, TAG_DONE);
  668. */
  669.   ScrWidth = GetCyberIDAttr(CYBRIDATTR_WIDTH,DispID);
  670.   ScrHeight = GetCyberIDAttr(CYBRIDATTR_HEIGHT,DispID);
  671.  
  672. PluginScreen = OpenScreenTags(NULL,
  673.                                      SA_Quiet,TRUE,
  674.                                      SA_Width,ScrWidth,
  675.                                      SA_Height,ScrHeight,
  676.                                      SA_Depth,8,
  677.                                      SA_DisplayID,DispID,
  678.                                      TAG_DONE);
  679.  
  680.   BytesPerRow = GetCyberMapAttr(PluginScreen->RastPort.BitMap,CYBRMATTR_XMOD);
  681.   GfxAddr = (BYTE *)GetCyberMapAttr(PluginScreen->RastPort.BitMap,CYBRMATTR_DISPADR);
  682.  
  683.         if(PluginScreen == NULL) {
  684.                 ShowRequester("Could not open screen!", "Abort");
  685.                 return(FALSE);
  686.         }
  687.  
  688.         rp = &PluginScreen->RastPort;
  689.         vp = &PluginScreen->ViewPort;
  690.  
  691.  
  692.         LoadRGB32(vp, Colour);
  693.  
  694.         PluginWin=OpenWindowTags(NULL, WA_CustomScreen, (ULONG)PluginScreen,
  695.                                        WA_Left,         0,
  696.                                        WA_Top,          0,
  697.                                        WA_Width,        Width,
  698.                                        WA_Height,       Height,
  699.                                        WA_SizeGadget,   FALSE,
  700.                                        WA_DragBar,      FALSE,
  701.                                        WA_DepthGadget,  FALSE,
  702.                                        WA_CloseGadget,  FALSE,
  703.                                        WA_Backdrop,     TRUE,
  704.                                        WA_Borderless,   TRUE,
  705.                                        WA_Activate,     TRUE,
  706.                                        WA_AutoAdjust,   TRUE,  // Just to be sure :-)
  707.                                        WA_IDCMP,        IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
  708.                                        TAG_DONE);
  709.         if(PluginWin == NULL) {
  710.                 ShowRequester("Could not open window!", "Abort");
  711.                 return(FALSE);
  712.         }
  713.  
  714.         SetPointer(PluginWin, EmptyPointer, 1, 1, 0, 0);
  715.         SetAPen(rp, 1);
  716.         RectFill(rp, 0, 0, (Width-1), (Height-1));
  717.         SetAPen(rp, 255);
  718.  
  719.         WinMask = 1L << PluginWin->UserPort->mp_SigBit;
  720.  
  721.         InitField(Zoom, Width, Height);
  722.         MakeTitle();
  723.  
  724.         return(TRUE);
  725. }
  726.  
  727. /******************************************************************************/
  728. /* This function will be called when the plugin is shut down. You should free */
  729. /* all previously allocated resources here.                                   */
  730. /******************************************************************************/
  731.  
  732. void PluginExit(void) {
  733.         long i;
  734.  
  735.         if(PluginWin)    CloseWindow(PluginWin);
  736.         if(PluginScreen) CloseScreen(PluginScreen);
  737.         #ifdef __SASC
  738.                 if(PixelD)       PPCFreeVec(PixelD);
  739.                 if(PixelC)       PPCFreeVec(PixelC);
  740.                 if(Colour)       PPCFreeVec(Colour);
  741.                 if(EmptyPointer) PPCFreeVec(EmptyPointer);
  742.         #else
  743.          #ifdef __PPC__ 
  744.                 if(PixelD)       FreeVecPPC(PixelD);
  745.                 if(PixelC)       FreeVecPPC(PixelC);
  746.                 if(Colour)       FreeVecPPC(Colour);
  747.                 if(EmptyPointer) FreeVecPPC(EmptyPointer);
  748.          #else
  749.                 if(PixelD)       FreeVec(PixelD);
  750.                 if(PixelC)       FreeVec(PixelC);
  751.                 if(Colour)       FreeVec(Colour);
  752.                 if(EmptyPointer) FreeVec(EmptyPointer);
  753.          #endif
  754.         #endif
  755.  
  756.         CloseTimer();
  757.         if(CyberGfxBase)  CloseLibrary(CyberGfxBase);
  758.         if(P96Base)    CloseLibrary(P96Base);
  759. //      if(GfxBase)       CloseLibrary(GfxBase);
  760.         if(AslBase)       CloseLibrary(AslBase);
  761.         if(IconBase)      CloseLibrary(IconBase);
  762.         if(KeymapBase)    CloseLibrary(KeymapBase);
  763.         if(GadToolsBase)  CloseLibrary(GadToolsBase);
  764. //      if(IntuitionBase) CloseLibrary(IntuitionBase);
  765. }
  766.  
  767. /*******************************************************************************/
  768. /* This is the main Plugin Loop. It will receive a signal matching PluginMask  */
  769. /* each time new spectral data is ready. The data is stored in two arrays,     */
  770. /* UWORD Spec[512] in structures DataL and DataR. The scale is logarithmic,    */
  771. /* 0 means below -96dB, 65535 means 0dB.                                       */
  772. /* No matter how long it takes until your plugin actually processes the data,  */
  773. /* the memory referenced by the array pointers always remains valid!           */
  774. /*                                                                             */
  775. /* Your plugin loop MUST quit when it receives SIGBREAKF_CTRL_C. If you've     */
  776. /* opened a window you should react to the close gadget as well. For full      */
  777. /* screen plugins I strongly recommend checking the ESC key.                   */
  778. /*******************************************************************************/
  779.  
  780. void PluginLoop(void) {
  781.         struct TextExtent te;
  782.         ULONG *PixelL = 0;
  783.         UBYTE *ActPixel;
  784.         ULONG Signals = 0;
  785.         LONG i,j,k;
  786.         LONG l,r;
  787.         LONG x,y;
  788.         UBYTE v;
  789.         UWORD w;
  790.         UBYTE ColorMode;
  791.  
  792.         ULONG   hi,lo,itime,eclock;
  793.         char FPStext[64];
  794.  
  795.         UBYTE Vanilla;
  796.         struct InputEvent ie;
  797.         WORD    RawLen;
  798.         printf("entering main loop\n");
  799.         Wait(SIGBREAKF_CTRL_C | PluginMask);
  800.  
  801.         /* Make a backup of the data pointers */
  802.         PluginRawL    = SpecRawL;
  803.         PluginRawR    = SpecRawR;
  804.         PluginSamples = SampleRaw;
  805.         WritePixelArray(PixelC, 0, 0, Width, rp, Woffset, 0, Width, Height, RECTFMT_LUT8);
  806.  
  807.         Delay(100);
  808.  
  809.         StartTimer();
  810.  
  811.         InitWave(WaveToCalc0, 0);
  812.         InitWave(WaveToCalc1, 1);
  813.  
  814.         for(;;) {
  815.                 /* Wait until there's something to do */
  816.  
  817.                 Signals=Wait(SIGBREAKF_CTRL_C | PluginMask | ConfigMask | InfoMask | WinMask | TimerMask);
  818.                 if(Signals & TimerMask) {
  819.                         WaitIO((struct IORequest *) TimerIO);
  820.                 }
  821.  
  822.                 /* Break received -> quit at once! */
  823.                 if(Signals & SIGBREAKF_CTRL_C) break;
  824.  
  825.                 /* Window close gadget hit -> quit as well! */
  826.                 if(Signals & WinMask) {
  827.                         struct IntuiMessage *imsg;
  828.                         BOOL done=0;
  829.  
  830.                         while(imsg=(struct IntuiMessage *)GetMsg(PluginWin->UserPort)) {
  831.                                 if(imsg->Class == IDCMP_RAWKEY) {
  832.                                         ie.ie_Class        = IECLASS_RAWKEY;
  833.                                         ie.ie_SubClass     = 0;
  834.                                         ie.ie_Code         = imsg->Code;
  835.                                         ie.ie_Qualifier    = 0;
  836.                                         ie.ie_EventAddress = imsg->IAddress;
  837.                                         RawLen = MapRawKey(&ie, &Vanilla, 1, 0);
  838.  
  839.                                         switch(imsg->Code) {
  840.                                                 case 0x45: done=1; break;
  841.                                         }
  842.  
  843.                                         if(RawLen==1) {
  844.                                                 switch(Vanilla) {
  845.                                                         case 'f': DisplayFPS = 1-DisplayFPS; break;
  846.                                                         case 'w': ShowWave   = 1-ShowWave;   break;
  847.                                                         case 'i': InfoCount  = 0;            break;
  848. //                                              case '+': Cutoff--;                  break;
  849. //                                              case '-': Cutoff++;                  break;
  850.                                                 }
  851.                                                 if(Cutoff < 1) Cutoff =   1;
  852.                                                 if(Cutoff > HalfHeight-10) Cutoff = HalfHeight-10;
  853.                                                 for(i=0; i<Width*Cutoff; i++) {
  854.                                                         PixelC[i]=PixelD[i]=0;
  855.                                                 }
  856.                                                 for(i=Width*(Height-Cutoff); i<Width*Height; i++) {
  857.                                                         PixelC[i]=PixelD[i]=0;
  858.                                                 }
  859.                                         }
  860.                                 }
  861.                                 ReplyMsg(imsg);
  862.                         }
  863.                         if(done) break;
  864.                 }
  865.  
  866.                 if(Signals & TimerMask) {
  867.                         StartTimer();
  868. //printf("timer started\n");
  869.       Blur(PixelC, PixelD);
  870.  
  871.                         FrameCountLow++;
  872.                         if(FrameCountLow > 4) {
  873.                                 FrameCountLow = 0;
  874.                                 eclock=ReadEClock(&ev2);
  875.                                 hi = ev2.ev_hi - ev1.ev_hi;
  876.                                 lo = ev2.ev_lo - ev1.ev_lo;
  877.                                 itime = hi*eclock+lo;
  878.  
  879.                                 if(itime==0) itime=1;
  880.  
  881.                                 ev1.ev_hi = ev2.ev_hi;
  882.                                 ev1.ev_lo = ev2.ev_lo;
  883.                                 ReColor();
  884.                         }
  885.  
  886.                         FrameCountHigh++;
  887.                 if(FrameCountHigh > 600) {
  888.                                 FrameCountHigh = 0;
  889. #ifndef __VBCC__
  890.                                 ColorMode = (UBYTE)(rand()>>24) % 10;
  891.  
  892. #else
  893. /*
  894. if(ColorMode==0)
  895. {
  896.         MidR[0] = 255;
  897.         MidG[0] = 220;
  898.         MidB[0] = 200;
  899.  
  900.         MidR[1] = 170;
  901.         MidG[1] = 96;
  902.         MidB[1] = 170;
  903.  
  904.         MidR[2] = 10;
  905.         MidG[2] = 100;
  906.         MidB[2] = 52;
  907.  
  908. ColorMode=1;
  909. }
  910. */
  911. /*
  912. if(ColorMode==0)
  913. {
  914.         MidR[0] = 255;
  915.         MidG[0] = 200;
  916.         MidB[0] = 255;
  917.  
  918.         MidR[1] = 96;
  919.         MidG[1] = 76;
  920.         MidB[1] = 178;
  921.  
  922.         MidR[2] = 100;
  923.         MidG[2] = 55;
  924.         MidB[2] = 65;
  925.  
  926. ColorMode=1;
  927. }
  928. */
  929.  
  930. if(ColorMode == 0)
  931. {
  932. //blue
  933.         MidR[0] = 230;
  934.         MidG[0] = 230;
  935.         MidB[0] = 230;
  936.  
  937.         MidR[1] = 86;
  938.         MidG[1] = 86;
  939.         MidB[1] = 170;
  940.  
  941.         MidR[2] = 25;
  942.         MidG[2] = 25;
  943.         MidB[2] = 100;
  944.  
  945. ColorMode = 1;
  946. }
  947. else
  948. {
  949. //fire
  950.         MidR[0] = 255;
  951.         MidG[0] = 255;
  952.         MidB[0] = 100;
  953.  
  954.         MidR[1] = 200;
  955.         MidG[1] = 120;
  956.         MidB[1] = 10;
  957.  
  958.         MidR[2] = 100;
  959.         MidG[2] = 25;
  960.         MidB[2] = 25;
  961.  
  962.         MidR[3] = 0;
  963.         MidG[3] = 0;
  964.         MidB[3] = 0;
  965.  
  966. ColorMode = 0;
  967. }
  968.  
  969. #endif
  970.                         printf("ColorMode: %d\n", ColorMode);
  971. #ifndef __VBCC__
  972.                                 switch(ColorMode) {
  973.                                         case 0:
  974.                                         case 1:
  975.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  976.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  977.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  978.  
  979.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  980.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  981.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  982.  
  983.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  984.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  985.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  986.                                         break;
  987.  
  988.                                         case 2:
  989.                                                 MidRdst[0] = (UBYTE)(rand()>>24) + 0;
  990.                                                 MidGdst[0] = (UBYTE)(rand()>>24) + 0;
  991.                                                 MidBdst[0] = (UBYTE)(rand()>>24) + 0;
  992.  
  993.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  994.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  995.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  996.  
  997.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  998.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  999.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  1000.                                         break;
  1001.  
  1002.                                         case 3:
  1003.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 0;
  1004.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 0;
  1005.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 0;
  1006.  
  1007.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  1008.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  1009.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  1010.  
  1011.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  1012.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  1013.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  1014.                                         break;
  1015.  
  1016.                                         default:
  1017.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  1018.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  1019.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  1020.  
  1021.                                                 MidRdst[1] = (UBYTE)(rand()>>25) + 64;
  1022.                                                 MidGdst[1] = (UBYTE)(rand()>>25) + 64;
  1023.                                                 MidBdst[1] = (UBYTE)(rand()>>25) + 64;
  1024.  
  1025.                                                 MidRdst[2] = (UBYTE)(rand()>>25) + 32;
  1026.                                                 MidGdst[2] = (UBYTE)(rand()>>25) + 32;
  1027.                                                 MidBdst[2] = (UBYTE)(rand()>>25) + 32;
  1028.                                         break;
  1029.                                 }
  1030. #endif
  1031.                         }
  1032.  
  1033.                         CalcLine(Zoom2, Width, Height, FieldToCalc);
  1034.                         LineToCalc++;
  1035.                         if(LineToCalc > Height-1) LineToCalc = Height-1;
  1036.                         FrameCountField++;
  1037.                         
  1038.                         if(FrameCountField > 500) {
  1039.  
  1040.                         printf("FCF 500\n");
  1041.                                 FrameCountField=0;
  1042.  
  1043.                                 LineToCalc = 1;
  1044.                                 PrevField = FieldToCalc;
  1045.  
  1046. #ifdef __VBCC__
  1047.                                 do {
  1048.                         FieldToCalc=(UBYTE)(rand() % NUMFIELDS);
  1049.                                 } while (FieldToCalc == PrevField);
  1050.  
  1051. /*                              if(FieldToCalc == 0)
  1052.                                 FieldToCalc = 1;
  1053.                                 else if(FieldToCalc == 1)
  1054.                                 FieldToCalc = 2;
  1055.                                 else if(FieldToCalc == 2)
  1056.                                 FieldToCalc = 3;
  1057.                                 else if(FieldToCalc == 3)
  1058.                                 FieldToCalc = 4;
  1059.                                 else if(FieldToCalc == 4)
  1060.                                 FieldToCalc = 6;
  1061.                                 else if(FieldToCalc == 6)
  1062.                                 FieldToCalc = 7;
  1063.                                 else if(FieldToCalc == 7)
  1064.                                 FieldToCalc = 9;
  1065.                                 else if(FieldToCalc == 9)
  1066.                                 FieldToCalc = 10;
  1067.                                 else if(FieldToCalc == 10)
  1068.                                 FieldToCalc = 13;
  1069.                                 else if(FieldToCalc == 13)
  1070.                                 FieldToCalc = 14;
  1071.                                 else if(FieldToCalc == 14)
  1072.                                 FieldToCalc = 15;
  1073.                                 else if(FieldToCalc == 15)
  1074.                                 FieldToCalc = 16;
  1075.                                 else if(FieldToCalc == 16)
  1076.                                 FieldToCalc = 18;
  1077.                                 else
  1078.                                 FieldToCalc = 0;
  1079. */
  1080. #endif
  1081.  
  1082. #ifndef __VBCC__
  1083.                                 do {
  1084.                         FieldToCalc=(UBYTE)(rand()>>24) % NUMFIELDS;
  1085.                                 } while (FieldToCalc == PrevField);
  1086. #endif
  1087.  
  1088.                                 for(j=0; j<Width*Height; j++)
  1089.                                 {
  1090.                                         Zoom[j]=Zoom2[j];
  1091.                                 }
  1092.                                 printf("preparing field %d\n", FieldToCalc);
  1093.                                 PrepareConstants(FieldToCalc);
  1094.  
  1095.                         }
  1096.  
  1097.                         for(i=Width*Cutoff; i<Width*(Height-Cutoff); i++) {
  1098.                                 PixelC[i]=PixelD[Zoom[i]];
  1099.                         }
  1100.  
  1101.  
  1102.                         /* Make a backup of the data pointers */
  1103.                         PluginRawL    = SpecRawL;
  1104.                         PluginRawR    = SpecRawR;
  1105.                         PluginSamples = SampleRaw;
  1106.  
  1107.                         InfoCount++;
  1108.                         if(InfoCount < 75) MakeTitle();
  1109.                         else InfoCount=75;
  1110.  
  1111.                         TimeWave++;
  1112.                         FrameCountWave++;
  1113.                         CalcWave(WaveToCalc0, 0);
  1114.                         DrawWave(WaveX,  WaveY,  Width, Height, WaveToCalc0, 0);
  1115.                         CalcWave(WaveToCalc1, 1);
  1116.                         DrawWave(WaveX2, WaveY2, Width, Height, WaveToCalc1, 1);
  1117.                         if(FrameCountWave > 200) {
  1118.  
  1119.                                 if(DestWaveBuffer == 1) WaveMorph += 0.015; //was 0.005
  1120.                                 else                    WaveMorph -= 0.015; //was 0.005
  1121.                         }
  1122.                         if (WaveMorph > 1.0) WaveMorph = 1.0;
  1123.                         if (WaveMorph < 0.0) WaveMorph = 0.0;
  1124.  
  1125.                         if(FrameCountWave > 400) {
  1126.                         printf("FCW 400\n");
  1127.                         FrameCountWave = 0;
  1128.                         DestWaveBuffer = 1 - DestWaveBuffer;
  1129. #ifdef __VBCC__
  1130.                                 do {
  1131.                                         WaveToCalc = (UBYTE)(rand() % NUMWAVES);
  1132.                                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1 || WaveToCalc == 10 || WaveToCalc == 8 || WaveToCalc == 6);
  1133.  
  1134.                                 if(DestWaveBuffer) {
  1135.                                         WaveToCalc1 = WaveToCalc;
  1136.                                         InitWave(WaveToCalc1, 1);
  1137.                                 }
  1138.                                 else {
  1139.                                         WaveToCalc0 = WaveToCalc;
  1140.                                         InitWave(WaveToCalc0, 0);
  1141.                                 }
  1142.  
  1143. /*
  1144. if (WaveToCalc1 == 1)
  1145. WaveToCalc1 = 5;
  1146. else if (WaveToCalc1 == 2)
  1147. WaveToCalc1 = 7;
  1148. else if (WaveToCalc1 == 3)
  1149. WaveToCalc1 = 11;
  1150. else if (WaveToCalc1 == 4)
  1151. WaveToCalc1 = 1;
  1152. else if (WaveToCalc1 == 5)
  1153. WaveToCalc1 = 2;
  1154. else if (WaveToCalc1 == 7)
  1155. WaveToCalc1 = 3;
  1156. else
  1157. WaveToCalc1 = 4;
  1158.  
  1159. WaveToCalc0 = 0;
  1160.  
  1161.         InitWave(WaveToCalc1, 1);
  1162.         printf("initializing wave %d\n",WaveToCalc1);
  1163.         InitWave(WaveToCalc0, 0);
  1164. */
  1165. #endif
  1166.  
  1167. #ifndef __VBCC__
  1168.                                 do {
  1169.                                         WaveToCalc = (UBYTE)(rand()>>24) % NUMWAVES;
  1170.                                         WaveToCalc = NUMWAVES-1;
  1171.                                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1);
  1172.  
  1173.                                 if(DestWaveBuffer) {
  1174.                                         WaveToCalc1 = WaveToCalc;
  1175.                                         InitWave(WaveToCalc1, 1);
  1176.                                 }
  1177.                                 else {
  1178.                                         WaveToCalc0 = WaveToCalc;
  1179.                                         InitWave(WaveToCalc0, 0);
  1180.                                 }
  1181. #endif
  1182.                         }
  1183.  
  1184.                         for(i=0; i<Width*2; i++) {
  1185.                                 float xf,yf;
  1186.                                 ULONG x,y;
  1187.                                 xf = (float)WaveX[i]*(1.0-WaveMorph) + (float)WaveX2[i]*(WaveMorph);
  1188.                                 yf = (float)WaveY[i]*(1.0-WaveMorph) + (float)WaveY2[i]*(WaveMorph);
  1189.                                 x  = (ULONG)xf + Width/2;
  1190.                                 y  = (ULONG)yf + Height/2;
  1191.                                 if(x < Width-1) {
  1192.                                         if(y < Height-1) {
  1193.                                                 if(x > 0) {
  1194.                                                         if(y > 0) {
  1195.                                                                 ActPixel = PixelC + y * Width + x;
  1196.                                                                 *ActPixel=255;
  1197.                                                         }
  1198.                                                 }
  1199.                                         }
  1200.                                 }
  1201.                         }
  1202.  
  1203.                         SetAPen(rp, 0);
  1204. /*                      if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1205.                         else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1206.                         RectFill(rp, 0, 0, Width, Cutoff);
  1207.                         RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1208. */
  1209.                         if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1210.                         else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1211.                         RectFill(rp, 0, 0, Width, Cutoff);
  1212.                         RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1213.  
  1214.  
  1215.  
  1216.  
  1217.                         if(DisplayFPS)
  1218.                         {
  1219.                                 Move(rp, 0, 15);
  1220.                                 SetABPenDrMd(rp, 255, 0, JAM2);
  1221.                                 sprintf(FPStext, "%3ld fps       ", 5*eclock/itime);
  1222.                                 Text(rp, FPStext, 7);
  1223.                         }
  1224.                 }
  1225.         }
  1226. }
  1227.  
  1228.  
  1229.  
  1230. void Blur(UBYTE *PixelC, UBYTE *PixelD) {
  1231.   UBYTE *ActPixel;
  1232.   UBYTE *DstPixel;
  1233.   UBYTE *AbovePixel, *BelowPixel;
  1234.   UBYTE Left, Act, Right;
  1235.   WORD w;
  1236.   ULONG i;
  1237.  
  1238.         PixelC += Width*Cutoff;
  1239.         PixelD += Width*Cutoff;
  1240.  
  1241.   ActPixel   = PixelC+Width+1;
  1242.   AbovePixel = ActPixel-Width;
  1243.   BelowPixel = ActPixel+Width;
  1244.   DstPixel   = PixelD+Width+1;
  1245.  
  1246.   Left  = 0;
  1247.   Act   = 0;
  1248.   Right = 0;
  1249.  
  1250.         for(i=Width*(Cutoff+1); i<(Width*(Height-Cutoff-2)-2); i++) {
  1251.     Right = *(ActPixel+1);
  1252.  
  1253.     w = (Right + Act + Left + *AbovePixel + *BelowPixel) * 3 / 16;
  1254.                 if(w<0) w=0;
  1255.     *DstPixel++ = w;
  1256.  
  1257.     ActPixel++;
  1258.     AbovePixel++;
  1259.     BelowPixel++;
  1260.  
  1261.     Left = Act;
  1262.     Act = Right;
  1263.   }
  1264. }
  1265.  
  1266. void ShowRequester(char *Text, char *Button) {
  1267.         struct EasyStruct Req;
  1268.         Req.es_StructSize   = sizeof(struct EasyStruct);
  1269.         Req.es_Flags        = 0;
  1270.   Req.es_Title        = "AmigaAMP Plugin";
  1271.   Req.es_TextFormat   = (UBYTE*)Text;
  1272.   Req.es_GadgetFormat = (UBYTE*)Button;
  1273.         EasyRequestArgs(NULL, &Req, NULL, NULL);
  1274. }
  1275.  
  1276. BOOL OpenTimer(void) {
  1277.         struct EClockVal ev = {0,0};
  1278.  
  1279.         if(TimerMP=(struct MsgPort*)CreatePort(0,0)) {
  1280.                 if(TimerIO=(struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest))) {
  1281.                         TimerError=OpenDevice("timer.device", UNIT_ECLOCK, (struct IORequest *)TimerIO, 0);
  1282.                         if(TimerError==0) {
  1283.  
  1284.                                 TimerBase = (struct Library*) &TimerIO->tr_node.io_Device->dd_Library;
  1285.                                 EFreq=ReadEClock(&ev);
  1286.  
  1287.                                 TimerMask = 1L << TimerMP->mp_SigBit;
  1288.  
  1289.                                 return(TRUE);
  1290.                         }
  1291.                 }
  1292.         }
  1293.         return(FALSE);
  1294. }
  1295.  
  1296. void CloseTimer(void) {
  1297.         if(!TimerError)   CloseDevice((struct IORequest *)TimerIO);
  1298.         if(TimerIO)       DeleteIORequest(TimerIO);
  1299.         if(TimerMP)       DeletePort(TimerMP);
  1300. }
  1301.  
  1302. void StartTimer(void) {
  1303.         TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  1304.         TimerIO->tr_node.io_Flags   = 0;
  1305.         TimerIO->tr_time.tv_secs    = 0;
  1306.         TimerIO->tr_time.tv_micro   = EFreq/LimitFPS;
  1307.         SendIO((struct IORequest *)TimerIO);
  1308. }
  1309.  
  1310. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri) {
  1311.         int sigBit;
  1312.         struct MsgPort *mp;
  1313.  
  1314.         if((sigBit = AllocSignal(-1L)) == -1)   return(NULL);
  1315.  
  1316.         mp = (struct MsgPort*) AllocVec(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);
  1317.  
  1318.         if(!mp) {
  1319.                 FreeSignal(sigBit);
  1320.                 return(NULL);
  1321.         }
  1322.  
  1323.         mp->mp_Node.ln_Name = name;
  1324.         mp->mp_Node.ln_Pri  = pri;
  1325.         mp->mp_Node.ln_Type = NT_MSGPORT;
  1326.         mp->mp_Flags        = PA_SIGNAL;
  1327.         mp->mp_SigBit       = sigBit;
  1328.         mp->mp_SigTask      = FindTask(NULL);
  1329.         if(name) AddPort(mp);
  1330.         #if defined (__SASC) || defined (__VBCC__)
  1331.                 else NewList(&(mp->mp_MsgList));
  1332.         #else
  1333.                 else NewListPPC(&(mp->mp_MsgList));
  1334.         #endif
  1335.  
  1336.         return(mp);
  1337. }
  1338.  
  1339. void MyDeletePort(struct MsgPort *mp) {
  1340.         if(mp->mp_Node.ln_Name) RemPort(mp);
  1341.         mp->mp_SigTask         = (struct Task *) -1;
  1342.         mp->mp_MsgList.lh_Head = (struct Node *) -1;
  1343.         FreeSignal(mp->mp_SigBit);
  1344.         FreeVec(mp); mp=NULL;
  1345. }
  1346.  
  1347. void InitField(LONG *Zoom, ULONG Width, ULONG Height) {
  1348.         LONG i,xs,ys,xd,yd;
  1349.  
  1350.         float scale,greater;
  1351.         float xsf,ysf,xdf,ydf;
  1352.         float rsf,tsf,rdf,tdf;
  1353.         float wf,hf;
  1354.  
  1355.         wf=(float)Width;
  1356.         hf=(float)Height;
  1357.  
  1358.         greater=1.0;
  1359.         if(wf > greater) greater = wf;
  1360.         if(hf > greater) greater = hf;
  1361.  
  1362.         scale = 1.0 / (greater/2.0);
  1363.  
  1364.         for(yd=0; yd<(Height); yd++) {
  1365.                 for(xd=0; xd<(Width); xd++) {
  1366.                         xdf = (xd - wf/2.0) * scale;
  1367.                         ydf = (yd - hf/2.0) * scale;
  1368.  
  1369.                         xsf = xdf - xdf * 0.075;
  1370.                         ysf = ydf - ydf * 0.075;
  1371.  
  1372.                         xs = xsf/scale + wf/2.0;
  1373.                         ys = ysf/scale + hf/2.0;
  1374.  
  1375.                         if(xs < Width/2)  xs++;
  1376.                         if(ys < Height/2) ys++;
  1377.  
  1378.                         if(xs < 0)      xs = 0;
  1379.                         if(xs > Width)  xs = Width;
  1380.                         if(ys < 0)      ys = 0;
  1381.                         if(ys > Height) ys = Height;
  1382.  
  1383.                         Zoom[Width * yd + xd] = Width * ys + xs;
  1384.                 }
  1385.         }
  1386. }
  1387.  
  1388.  
  1389. void MakeCMap(void) {
  1390.         int j,i,c;
  1391.         float r,g,b;
  1392.         float rs,gs,bs;
  1393.  
  1394.         r=255; g=255; b=255;
  1395.  
  1396.         c=255;
  1397.  
  1398.         Colour[0]=256L<<16+0;
  1399.  
  1400.         for(j=0; j<4; j++) {
  1401.                 rs = (r - (float)MidR[j]) / 64.0;
  1402.                 gs = (g - (float)MidG[j]) / 64.0;
  1403.                 bs = (b - (float)MidB[j]) / 64.0;
  1404.                 for(i=0; i<64; i++) {
  1405.                         Colour[1+3*c+0] = (ULONG)r << 24;
  1406.                         Colour[1+3*c+1] = (ULONG)g << 24;
  1407.                         Colour[1+3*c+2] = (ULONG)b << 24;
  1408.                         r -= rs;
  1409.                         g -= gs;
  1410.                         b -= bs;
  1411.                         c--;
  1412.                 }
  1413.         }
  1414.  
  1415. }
  1416.  
  1417. void MakeTitle(void) {
  1418.         long x,y,i,p,s,v,xs,ys;
  1419.         UWORD Blt1[27] = {
  1420.                 0x7008,0x0000,0x0000,0x8808,0x0000,0x0000,0x822B,0x1963,
  1421.                 0x8E38,0x722C,0xA590,0x5144,0x0A28,0x9913,0xD07C,0x8A28,
  1422.                 0x8514,0x5040,0x8A68,0xA594,0xD144,0x71AF,0x1963,0x4E38,
  1423.                 0x0000,0x0100,0x0000
  1424.         }; // W=46, H=9
  1425.         UWORD Blt2[54] = {
  1426.                 0x8001,0xF400,0x0000,0x0101,0x0000,0x0080,0x8000,0x4400,
  1427.                 0x0000,0x0111,0x0000,0x0080,0xB220,0x458E,0x7638,0xC111,
  1428.                 0x3967,0x9C80,0xCA20,0x4651,0x4905,0x2092,0x4590,0xA280,
  1429.                 0x8940,0x4451,0x493C,0xC0AA,0x7D11,0x3E80,0x8940,0x4451,
  1430.                 0x4944,0x20AA,0x4112,0x2080,0x8880,0x4451,0x494D,0x2044,
  1431.                 0x4514,0x2280,0xF080,0x444E,0x4934,0xC044,0x3917,0x9C80,
  1432.                 0x0100,0x0000,0x0000,0x0000,0x0000,0x0000
  1433.         }; // W=89, H=9
  1434.  
  1435.         xs = (Width-46)/2;
  1436.         ys = Height/2-30-9;
  1437.         s=0;
  1438.         for(y=0; y<9; y++) {
  1439.                 x=0;
  1440.                 for(i=0; i<3; i++) {
  1441.                         for(p=0; p<16; p++) {
  1442.                                 x++;
  1443.                                 v = Blt1[s] & (1<<(15-p));
  1444.                                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1445.                         }
  1446.                         s++;
  1447.                 }
  1448.         }
  1449.         xs = (Width-89)/2;
  1450.         ys = Height/2+30;
  1451.         s=0;
  1452.         for(y=0; y<9; y++) {
  1453.                 x=0;
  1454.                 for(i=0; i<6; i++) {
  1455.                         for(p=0; p<16; p++) {
  1456.                                 x++;
  1457.                                 v = Blt2[s] & (1<<(15-p));
  1458.                                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1459.                         }
  1460.                         s++;
  1461.                 }
  1462.         }
  1463. }
  1464.  
  1465.  
  1466. void ReColor(void) {
  1467. #ifndef __VBCC__
  1468.  
  1469.         int i;
  1470.         for(i=0; i<3; i++) {
  1471.                 if(MidR[i] > MidRdst[i]) MidR[i] --;
  1472.                 if(MidG[i] > MidGdst[i]) MidG[i] --;
  1473.                 if(MidB[i] > MidBdst[i]) MidB[i] --;
  1474.                 if(MidR[i] < MidRdst[i]) MidR[i] ++;
  1475.                 if(MidG[i] < MidGdst[i]) MidG[i] ++;
  1476.                 if(MidB[i] < MidBdst[i]) MidB[i] ++;
  1477.  
  1478.         }
  1479. #endif
  1480.         MakeCMap();
  1481.         LoadRGB32(&PluginScreen->ViewPort, Colour);
  1482. }
  1483.  
  1484. float rnd(float max) {
  1485.         ULONG r;
  1486.         ULONG m;
  1487.  
  1488.         m = (ULONG)(max * 10000.0);
  1489. #ifndef __VBCC__
  1490.         r=(rand()>>8) % m;
  1491. #else
  1492.         r=(rand() % m);
  1493. #endif
  1494.         return (float)r/10000.0;
  1495. }
  1496.  
  1497. float sgn(float val) {
  1498.         if(val > 0.0) return  1.0;
  1499.         if(val < 0.0) return -1.0;
  1500.         return 0.0;
  1501. }
  1502.  
  1503. float trnc(float value) {
  1504.         return ceil(value);
  1505. }
  1506.  
  1507. #ifdef __SASC
  1508. void SetPriority(void) {
  1509.         struct TagItem MyTags[2];
  1510.         if(PPCLibBase=OpenLibrary("ppc.library",0)) {
  1511.                 MyTags[0].ti_Tag  = PPCTASKTAG_PRIORITY;
  1512.                 MyTags[0].ti_Data = 15;
  1513.                 MyTags[1].ti_Tag         = TAG_END;
  1514.                 CloseLibrary(PPCLibBase);
  1515.         }
  1516. }
  1517. #endif
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.